// pages/first/index.js
const request = require('../../assets/js/request.js');
const api = require('../../assets/js/api.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
      imgList:[],
      firstImgList:[],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getImg()
    this.getFirstImg()
  },
  getImg: function () {
    let that = this
    request._get(api.bgImg).then((res) => {
      console.log("datares")
      console.log(res)
      that.setData({
        imgList: res.data.data.image
      })
    })
  },
  getFirstImg: function () {
    let that = this
    request._get(api.firstImg).then((res) => {
      console.log("datares")
      console.log(res)
      that.setData({
        firstImgList: res.data.data.firstImg
      })
    })
    request._get(api.goodsList).then((res) => {
      console.log("goodsList")
      console.log(res)
      that.setLocalData(res.data.data.goods)
    })
  },
  setLocalData: function (data) {
    let that = this
    wx.setStorage({
      key: 'goodsList',
      data: data,
    })
    that.setData({
      goodsList: data
    })
  },
  //显示详情
   showDetail: function (e) {
    console.log(e)
    wx.navigateTo({
      url: '/pages/detail/index?id=' + e.currentTarget.dataset.id,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})